package com.seocoo.worker.order.adapter;

import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.seocoo.worker.R;
import com.seocoo.worker.order.entity.RspGoldInstall;
import com.seocoo.worker.order.widget.OrderDetailAddressView;
import com.seocoo.worker.order.widget.rsp.RspOrderDetailAddress;

/**
 * author : Ssp
 * e-mail : 981297079@qq.com
 * date   : 2020/2/2320:32
 * desc   : 订单(测量工匠)
 * version: 1.0
 */
public class OrderGoldAdapter extends BaseQuickAdapter<RspGoldInstall, BaseViewHolder> {

    public OrderGoldAdapter() {
        super(R.layout.order_gold_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, RspGoldInstall item) {
        helper.setText(R.id.tv_time, item.getAddTime())
                .setText(R.id.tv_cargo_num, "共" + item.getGoodsCount() + "件商品");
        initAddressView(helper, item);
        initBottomView(helper, item);

        if (TextUtils.isEmpty(item.getCommission())) {
            helper.setGone(R.id.tv_money1, false);
            helper.setGone(R.id.tv_money, false);
        } else {
            helper.setGone(R.id.tv_money1, true);
            helper.setGone(R.id.tv_money, true);
            helper.setText(R.id.tv_money, "佣金￥" + item.getCommission());
        }
    }

    /**
     * 设置地址栏数据
     */
    private void initAddressView(BaseViewHolder helper, RspGoldInstall item) {
        OrderDetailAddressView addressView = helper.getView(R.id.order_detail_address_view);
        RspOrderDetailAddress rspOrderDetailAddress = new RspOrderDetailAddress();
        rspOrderDetailAddress.setCargoAddress(item.getMerchantName());
        rspOrderDetailAddress.setCargoAddressDetail(item.getMerchantProvince() + item.getMerchantCity() + item.getMerchantDistrict() + item.getMerchantAddress());
        rspOrderDetailAddress.setUserAddress(item.getUserProvince() + item.getUserCity() + item.getUserDistrict() + item.getUserCommunity() + item.getUserDoorPlate());
        rspOrderDetailAddress.setUserName(item.getConsignee());
        rspOrderDetailAddress.setUserPhone(item.getContact());
        rspOrderDetailAddress.setMerchantContact(item.getMerchantContact());
        rspOrderDetailAddress.setPickupCode(item.getPickupCode());
        String orderStatus = item.getOrderStatus();
        if (!TextUtils.isEmpty(orderStatus)) {
            rspOrderDetailAddress.setOrderStatus(Integer.parseInt(orderStatus));
            if (Integer.parseInt(orderStatus) > 101) {
                addressView.getTv_user_phone().setVisibility(View.VISIBLE);
            } else {
                addressView.getTv_user_phone().setVisibility(View.GONE);
            }
        }
        addressView.initData(rspOrderDetailAddress);
    }

    private void initBottomView(BaseViewHolder helper, RspGoldInstall data) {
        helper.addOnClickListener(R.id.tv_cancel)
                .addOnClickListener(R.id.tv_receiving)
                .addOnClickListener(R.id.tv_appointment_install_time)
                .addOnClickListener(R.id.tv_relevance_friends);

        //301 待付款-无
        //402 待取货-无
        //501 待评价-无
        //502 已评价-无
        String status = data.getOrderStatus();
        String measureTime = data.getMeasureTime();
        if (TextUtils.equals("201", status) && TextUtils.isEmpty(measureTime)) {
            //201 测量中-取消测量、设置测量时间（测量时间为空的时候）
            helper.setGone(R.id.tv_relevance_friends, true);
        } else {
            helper.setGone(R.id.tv_relevance_friends, false);
        }

        if (TextUtils.equals("201", status) || TextUtils.equals("202", status)) {
            //201 202 测量中-取消测量、设置测量时间（测量时间为空的时候）
            helper.setGone(R.id.tv_cancel, true);
        } else {
            helper.setGone(R.id.tv_cancel, false);
        }

        if (TextUtils.equals("201", status) && !TextUtils.isEmpty(measureTime)) {
            //201 测量中-输入测量结果（测量时间不为空）
            helper.setGone(R.id.tv_appointment_install_time, true);
        } else {
            helper.setGone(R.id.tv_appointment_install_time, false);
        }

        if (TextUtils.equals("101", status)) {
            //101 待接单-接单
            helper.setGone(R.id.tv_receiving, true);
        } else {
            helper.setGone(R.id.tv_receiving, false);
        }
        boolean a = TextUtils.equals("400", status);
        boolean b = TextUtils.equals("401", status);
        boolean c = TextUtils.equals("403", status);
        boolean d = !TextUtils.isEmpty(data.getInstallTime());

        if ((a || b || c) && d) {
            //400 401 403 待安装-根据预约安装时间（ installTime）不为空展示 “已预约安装时间”
            helper.setGone(R.id.tv_appointment_installed_time, true);
        } else {
            helper.setGone(R.id.tv_appointment_installed_time, false);
        }

    }
}
